class Person:
    '''Represents a person.'''
    population = 0

    def __init__(self, name):
        '''Initializes the person's data.'''
        self.name = name
        print( '(Initializing %s)' % self.name)

        # When this person is created, he/she
        # adds to the population
        Person.population += 1

    def __del__(self):
        '''I am dying.'''
        print( '%s says bye.' % self.name)

        Person.population -= 1

        if Person.population == 0:
            print( 'I am the last one.')
        else:
            print( 'There are still %d people left.' % Person.population)

    def sayHi(self):
        '''Greeting by the person.

        Really, that's all it does.'''
        print( 'Hi, my name is %s.' % self.name)

    def howMany(self):
        '''Prints the current population.'''
        if Person.population == 1:
            print( 'I am the only person here.')
        else:
            print( 'We have %d persons here.' % Person.population)

swaroop = Person('Swaroop')
swaroop.sayHi()
swaroop.howMany()

kalam = Person('Abdul Kalam')
kalam.sayHi()
kalam.howMany()

swaroop.sayHi()
swaroop.howMany()


print('---------------------------')
poem = '''\
Programming is fun
When the work is done
if you wanna make your work also fun:
        use Python!
'''
filePath = 'data/poem.txt'
f = open(filePath, 'w') # open for 'w'riting
f.write(poem) # write text to file
f.close() # close the file

f = open(filePath)
# if no mode is specified, 'r'ead mode is assumed by default
while True:
    line = f.readline()
    if len(line) == 0: # Zero length indicates EOF
        break
    print (line),
    # Notice comma to avoid automatic newline added by Python
f.close() # close the file 

print('---------------------------')



help('pickle.dump')
import pickle as p
shoplistfile = 'data/shoplist.data'
shoplist = ['apple', 'mango', 'carrot']
f = open(shoplistfile, 'wb')
p.dump(shoplist, f)
f.close()
del shoplist
f = open(shoplistfile, 'rb')
#storedlist=1
storedlist = p.load(f)
print (storedlist) 
print('---------------------------')




